<?php

namespace app\admin\controller;

use app\admin\model\Category;
use app\admin\model\repair\Repair as model_Repair;
use app\admin\model\Staff;
use app\BaseController;
use app\Request;
class Repair extends BaseController
{

    public function repairList(){


        if(\request()->isAjax() && \request()->isGet()){

            $result=model_Repair::getList();

            return $this->success($result);
        }

        return view();
    }

    public function editRepair(Request $request)
    {



        $id= input('id');
        if($request->isPost() && $request->isAjax()){

            $id= input('id');

            $input=$request->post('');
            unset($input['file']);
            $input['expend_voucher'] &&  $input['expend_voucher']=explode(',',$input['expend_voucher']);
            $input['thubms'] && $input['thubms']=explode(',',$input['thubms']);
            empty($id) ? $type='add':$type='edit';
            if($type=='add'){
                $result= model_Repair::insertRepair($input);
                return $this->success($result);
            }else{

                $result= model_Repair::updateRepair($input);
                return $this->success($result);
            }
        }


        $info=model_Repair::where(['id'=>$id])->find();
        if($id){
            $info['list_expend_voucher'] =$info->getData('expend_voucher');
            $info['list_thubms'] =$info->getData('thubms');
            $info['cate_id'] =$info->getData('cate_id');
            $info['staff_ids'] =$info->getOrigin('staff_id');
        }


        empty($id) ? $tpl='add_repair':$tpl='edit_repair';

        $category=Category::categoryList();

        $status=config('view.Goods_status');

        $staff=Staff::getList();



        return view($tpl,['status'=>$status,'info'=>$info,'category'=>$category,'staff'=>$staff]);

    }


}